<?php
	require_once ("../include/db_info.inc.php");
	require_once ("../include/problem.php");
	if (!(isset($_SESSION['administrator']))){
	    echo "<a href='../loginpage.php'>Please Login First!</a>";
	    exit(1);
	}
	$id = (int)$_POST['id'];
	$filename = $_POST['file'];
	$input = $_POST['input'];
	$output = $_POST['output'];
	
	$sql = "SELECT `author` FROM `problem` where `problem_id`={$id}";
	$result = mysql_query($sql);
	$row = mysql_fetch_array($result);
	if ($row['author'] != $_SESSION['user_id'] && !$_SESSION['system'] && !$_SESSION['problem_manager']){
		echo "You Cannot Edit Data!";
		exit(0);
	}

	if (get_magic_quotes_gpc()){
		$filename = stripslashes ($filename);
		$input = stripslashes ($input);
		$output = stripslashes ($output);
	}
	
	if (strpos($filename, "/") || strpos($filename, "\\")){
		echo "Filename Error!";
		exit(1);
	}

	$path = $OJ_DATA . '/' . $id . '/' . $filename;
	
	mkdata($id, $filename . ".in", $input, $OJ_DATA);
	mkdata($id, $filename . ".out", $output, $OJ_DATA);
	ojlog("Change Problem Data:" . $id);
	header("location: problem_data_edit_page1.php?id={$id}");
